package com.boot2.controller.resp;

import com.boot2.pojo.Address;
import com.boot2.pojo.Result;
import com.boot2.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wzm
 * @create 2023-11-29 15:32
 * project_name:web2310
 * @Description
 */

@RestController
public class RespController01 {
    //响应字符串到浏览器
    @RequestMapping("/str")
    public Result hello(){
//        return "hello";
        //返回了带有数据hello的result对象
//        return new Result(1,"success","hello");
        return Result.success("hello");
    }

    //响应实体对象到浏览器
    @RequestMapping("/obj")
    public Result getAddr(){
        Address address = new Address();
        address.setProvince("广东");
        address.setCity("东莞");
//        return address;
//        return new Result(1,"success",address);
        return Result.success(address);
    }

    //响应集合数据
    @RequestMapping("/list")
    public Result getList(){
        List<Address> list = new ArrayList<>();
        Address address = new Address();
        address.setProvince("广东");
        address.setCity("东莞");
        list.add(address);

        Address address1 = new Address();
        address.setProvince("广东1");
        address.setCity("东莞1");
        list.add(address1);
        //return list;//返回集合
// return new Result(1,"success",list);
        //return Result.error("密码错误");
        return Result.success(list);
    }
}
